🎖️GitЯра🎖️
Node / meshtastic / Meshtastic-Android / files / core / model / src / commonMain / kotlin / org / meshtastic / core / model / RegionPresetConstraint.kt
Displaying Raw • Download
core/model/src/commonMain/kotlin/org/meshtastic/core/model/RegionPresetConstraint.kt 2d20cd8a4708e2ef66e98d5259f3a97ec93f240a (2d20cd8a) Text, 4.46 KB
T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.core.model
Tff7b72import T7ee787org.meshtastic.proto.Config.LoRaConfig.ModemPreset
Tff7b72import T7ee787org.meshtastic.proto.Config.LoRaConfig.RegionCode
Tff7b72import T7ee787org.meshtastic.proto.LoRaRegionPresetMap
T8b949e/**
* The modem presets the firmware advertised as legal for one LoRa region, decoded from a [LoRaRegionPresetMap].
*
* @property presets the presets that are legal in the region.
* @property defaultPreset the firmware's default preset for the region (always one of [presets]).
* @property licensedOnly true when the region's presets are for licensed operators only (e.g. amateur bands); the whole
* group is gated, not individual presets.
*/
Tff7b72data Tff7b72class T56d364RegionPresetConstraintTb4b4b4(
Tff7b72val Te6edf3presetsTb4b4b4: Te6edf3ListTff7b72<Te6edf3ModemPresetTff7b72>Tb4b4b4,
Tff7b72val Te6edf3defaultPresetTb4b4b4: Te6edf3ModemPresetTb4b4b4,
Tff7b72val Te6edf3licensedOnlyTb4b4b4: Tffa657BooleanTb4b4b4,
Tb4b4b4) Tb4b4b4{
T8b949e/** True when an operator with the given licensing state may not select any preset in this region. */
Tff7b72fun Td2a8ffisGatedTb4b4b4(Te6edf3isLicensedTb4b4b4: Tffa657BooleanTb4b4b4)Tb4b4b4: Tffa657Boolean Tff7b72= Te6edf3licensedOnly Tff7b72&Tff7b72& Tff7b72!Te6edf3isLicensed
Tb4b4b4}
T8b949e/**
* Resolves the [RegionPresetConstraint] the firmware advertised for [region], or `null` when there is no constraint
* information and the client must therefore NOT restrict the preset list. A `null` result happens when:
* - the map is `null` (firmware older than 2.8 never sends it),
* - [region] is absent from `region_groups` (no firmware table entry — treated as unconstrained),
* - the referenced `group_index` is out of range (defensive against a malformed map), or
* - the referenced group has no presets (a degenerate/malformed group — must not collapse the picker to nothing).
*/
Tf0883e@SuppressTb4b4b4(Ta5d6ff"Ta5d6ffReturnCountTa5d6ff"Tb4b4b4) T8b949e// Guard clauses for defensive null checks and missing lookups are idiomatic
Tff7b72fun Td2a8ffLoRaRegionPresetMapTff7b72?.Te6edf3constraintForTb4b4b4(Te6edf3regionTb4b4b4: Te6edf3RegionCodeTb4b4b4)Tb4b4b4: Te6edf3RegionPresetConstraint? Tb4b4b4{
Tff7b72if Tb4b4b4(Tff7b72this Tff7b72=Tff7b72= Tff7b72nullTb4b4b4) Tff7b72return Tff7b72null
Tff7b72val Te6edf3entry Tff7b72= Te6edf3region_groupsTb4b4b4.Te6edf3firstOrNull Tb4b4b4{ Tffa657itTb4b4b4.Te6edf3region Tff7b72=Tff7b72= Te6edf3region Tb4b4b4} Tff7b72?: Tff7b72return Tff7b72null
Tff7b72val Te6edf3group Tff7b72= Te6edf3groupsTb4b4b4.Te6edf3getOrNullTb4b4b4(Te6edf3entryTb4b4b4.Te6edf3group_indexTb4b4b4)Tff7b72?.Te6edf3takeIf Tb4b4b4{ Tffa657itTb4b4b4.Te6edf3presetsTb4b4b4.Te6edf3isNotEmptyTb4b4b4(Tb4b4b4) Tb4b4b4} Tff7b72?: Tff7b72return Tff7b72null
Tff7b72return Te6edf3RegionPresetConstraintTb4b4b4(
Te6edf3presets Tff7b72= Te6edf3groupTb4b4b4.Te6edf3presetsTb4b4b4,
Te6edf3defaultPreset Tff7b72= Te6edf3groupTb4b4b4.Te6edf3default_presetTb4b4b4,
Te6edf3licensedOnly Tff7b72= Te6edf3groupTb4b4b4.Te6edf3licensed_onlyTb4b4b4,
Tb4b4b4)
Tb4b4b4}
T8b949e/**
* Returns the modem preset the LoRa form should hold for [region] given the currently-selected [current] preset.
*
* Keeps [current] when it is still legal in [region]; otherwise falls back to the region's default preset (and, if that
* is somehow not in the legal set, the first legal preset). Returns [current] unchanged when [region] is unconstrained.
* Licensing is intentionally NOT considered here — auto-swap is about legality; selectability is decided separately by
* [RegionPresetConstraint.isGated].
*/
Tff7b72fun Td2a8ffLoRaRegionPresetMapTff7b72?.Te6edf3repairPresetForTb4b4b4(Te6edf3regionTb4b4b4: Te6edf3RegionCodeTb4b4b4, Te6edf3currentTb4b4b4: Te6edf3ModemPresetTb4b4b4)Tb4b4b4: Te6edf3ModemPreset Tb4b4b4{
Tff7b72val Te6edf3constraint Tff7b72= Te6edf3constraintForTb4b4b4(Te6edf3regionTb4b4b4) Tff7b72?: Tff7b72return Te6edf3current
Tff7b72return Tff7b72when Tb4b4b4{
Te6edf3current Tff7b72in Te6edf3constraintTb4b4b4.Te6edf3presets Tff7b72-Tff7b72> Te6edf3current
Te6edf3constraintTb4b4b4.Te6edf3defaultPreset Tff7b72in Te6edf3constraintTb4b4b4.Te6edf3presets Tff7b72-Tff7b72> Te6edf3constraintTb4b4b4.Te6edf3defaultPreset
Tff7b72else Tff7b72-Tff7b72> Te6edf3constraintTb4b4b4.Te6edf3presetsTb4b4b4.Te6edf3firstOrNullTb4b4b4(Tb4b4b4) Tff7b72?: Te6edf3current
Tb4b4b4}
Tb4b4b4}
T8b949e/**
* The app's built-in default modem presets for regions whose default differs from the global [ChannelOption.DEFAULT].
* Mirrors the per-region defaults newer firmware advertises in [LoRaRegionPresetMap], so the default channel and a
* fresh setup over old firmware (which sends no map) land on the same preset a new node would.
*/
Tff7b72private Tff7b72val Te6edf3REGION_DEFAULT_PRESETS Tff7b72= Te6edf3mapOfTb4b4b4(Te6edf3RegionCodeTb4b4b4.Te6edf3US Te6edf3to Te6edf3ModemPresetTb4b4b4.Te6edf3LONG_TURBOTb4b4b4)
T8b949e/**
* The app's preferred default preset for [region], or `null` when it has no region-specific default and the caller
* should fall back to [ChannelOption.DEFAULT] / the current preset.
*/
Tff7b72fun Td2a8ffdefaultPresetForTb4b4b4(Te6edf3regionTb4b4b4: Te6edf3RegionCodeTb4b4b4)Tb4b4b4: Te6edf3ModemPreset? Tff7b72= Te6edf3REGION_DEFAULT_PRESETSTff7b72[Te6edf3regionTff7b72]
Served by rngit 1.5.0 - Generated in 0.04s